import java.util.List;

public class Iterator implements IIterator {
    private List<Object> products;
    private int cursornext;
    private int cursorprevious;

    public Iterator(ProductList list) {
        this.products = list.getObjects();
        cursornext = 0;
        cursorprevious = products.size() -1;
    }

    public void next() {
        if(cursornext < products.size()) {
            cursornext++;
        }
    }

    public boolean isLast() {
        return (cursornext == products.size());
    }

    public void previous() {
        if (cursorprevious > -1) {
            cursorprevious--;
        }
    }

    public boolean isFirst() {
        return (cursorprevious == -1);
    }

    public Object getNextItem() {
        return products.get(cursornext);
    }

    public Object getPreviousItem() {
        return products.get(cursorprevious);
    }

}
